package com.le.tester.javaThink.fifth.chapter24_ConcurrentProgramming;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.IntStream;

/**
 * createTime：2021/8/18 9:17
 * description：线程直接收shutdown
 */
public class SingleThreadExecutor2 {
    public static void main(String[] args) {

        ExecutorService executorService = Executors.newSingleThreadExecutor();
        IntStream.range(0,10)
                .mapToObj(NapTask::new)
                .forEach(executorService::execute);
        //线程的直接shutdown,再这个尝试提交任务的瞬间，有可能会抛出RejectedExecutionException
        executorService.shutdown();
    }
}
